package com.gome.ocean.server.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gome.ocean.dao.cango.CangoTableDAO;
import com.gome.ocean.dao.model.cango.CangoTable;
import com.gome.ocean.server.service.ICangoTableService;

/**
 * @author zhangguoqing 2017年2月15日 下午5:21:22
 * @since 5.0.0
 */
@Service("iCangoTableService")
public class CangoTableServiceImpl implements ICangoTableService {

    @Autowired
    private CangoTableDAO cangoTableDao;

    @Override
    public boolean insert(CangoTable table) {
        boolean flag = false;
        try {
            cangoTableDao.insert(table);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean update(CangoTable table) {
        boolean flag = false;
        try {
            cangoTableDao.update(table);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean deleteById(Long id) {
        boolean flag = false;
        try {
            cangoTableDao.deleteById(id);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean deleteByInstancesName(String instancesName) {
        boolean flag = false;
        try {
            cangoTableDao.deleteByInstancesName(instancesName);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public CangoTable getBeanByMap(Map<String, Object> map) {
        return cangoTableDao.getBeanByMap(map);
    }

    @Override
    public List<CangoTable> getBeanListsByName(String instancesName) {
        try {
            List<CangoTable> list = cangoTableDao.getBeanListsByName(instancesName);
            if (list != null && list.size() > 0) {
                return list;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void deleteAll() {
        cangoTableDao.deleteAll();
    }

    @Override
    public void batchSave(List<CangoTable> tables) {
        if (tables != null && tables.size() > 0) {
            for (CangoTable table : tables) {
                cangoTableDao.insert(table);
            }
        }
    }

}
